bitkeeper revision 1.599 (3fb3783bCzU2OI0iS1r2i_GVLKRG0Q)
authorlaudney@eclipse.(none) <laudney@eclipse.(none)>
Thu, 13 Nov 2003 12:25:31 +0000 (12:25 +0000)
committerlaudney@eclipse.(none) <laudney@eclipse.(none)>
Thu, 13 Nov 2003 12:25:31 +0000 (12:25 +0000)
Fixes. Xen console buffer ring can be cleared at request.

tools/internal/xi_read_console_ring.c
xen/common/console.c
xen/common/dom0_ops.c
xen/include/hypervisor-ifs/dom0_ops.h
xen/include/xeno/console.h

index eaa73aed92f863a7660c438ae3516528976efee2..b8ddf0695fa75e2dda108196489ff93229c9de74 100644 (file)
@@ -4,10 +4,12 @@
 
 #include "dom0_defs.h"
 
-#define CONSOLE_RING_SIZE 16392
+#define CONSOLE_RING_SIZE      16392
+#define CONSOLE_RING_CLEAR     1
+
 static char *argv0 = "read_console_ring";
 
-static long read_console_ring(unsigned long str, unsigned count)
+static long read_console_ring(unsigned long str, unsigned count, unsigned int cmd)
 {
     int ret;
     dom0_op_t op;
@@ -15,6 +17,7 @@ static long read_console_ring(unsigned long str, unsigned count)
     op.cmd = DOM0_READCONSOLE;
     op.u.readconsole.str = str;
     op.u.readconsole.count = count;
+    op.u.readconsole.cmd = cmd;
 
     ret = do_dom0_op(&op);
     if (ret > 0) {
@@ -26,22 +29,32 @@ static long read_console_ring(unsigned long str, unsigned count)
 
 int main(int argc, char **argv)
 {
-    char str[CONSOLE_RING_SIZE];
-
+    char str[CONSOLE_RING_SIZE+1];
+    unsigned int cmd = 0;
+    
     if ( argv[0] != NULL ) 
         argv0 = argv[0];
     
-    if ( argc > 2) {
-        fprintf(stderr, "Usage: %s [-r]\n", argv0);
+    if ( argc > 2 || (argc == 2 && strcmp(argv[1], "-c")) ) {
+        fprintf(stderr, "Usage: %s [-c]\n", argv0);
+        return 1;
+    }
+
+    if ( argc == 2) {
+       cmd |= CONSOLE_RING_CLEAR;
+    }
+    
+    if ( mlock(str, CONSOLE_RING_SIZE+1) != 0) {
+        PERROR("Could not lock memory for user space read console ring buffer");
         return 1;
     }
     
-    if ( read_console_ring((unsigned long)str, CONSOLE_RING_SIZE) < 0 ) {
+    if ( read_console_ring((unsigned long)str, CONSOLE_RING_SIZE, cmd) < 0 ) {
        printf("Read console ring error.\n");
-       printf("%s", str);
         return 1;
     }
 
     printf("%s", str);
+       
     return 0;
 }
index f6e3f250bbdb904cc48f3daed341e69607e0b054..d52a8cf3be0e363d1288d35ddb57601d01bbeda2 100644 (file)
@@ -12,19 +12,18 @@ console_ring_t console_ring = {
     .len = 0
 };
 
-void init_console_ring()
-{
-    console_ring.len = 0;
-}
-
-long read_console_ring(unsigned long str, unsigned int count)
+long read_console_ring(unsigned long str, unsigned int count, unsigned cmd)
 {
     unsigned int len;
     
-    len = (console_ring.len < count)? console_ring.len : count;
+    len = (console_ring.len < count) ? console_ring.len : count;
     
     if ( copy_to_user((char *)str, console_ring.buf, len) )
         return -EFAULT;
 
+    if ( cmd & CONSOLE_RING_CLEAR ) {
+       console_ring.len = 0;
+    }
+    
     return len;
 }
index 0558a1e40b5d7f231cdc73ca5d151764d1b79510..8db4b5fedbc720b44091c864cf58bc5e9b914b3b 100644 (file)
@@ -415,9 +415,10 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
     
     case DOM0_READCONSOLE:
     {
-       extern long read_console_ring(unsigned long, unsigned int);
+       extern long read_console_ring(unsigned long, unsigned int, unsigned int);
         ret = read_console_ring(op.u.readconsole.str, 
-                               op.u.readconsole.count); 
+                               op.u.readconsole.count,
+                               op.u.readconsole.cmd); 
     }
     break;    
 
index 770305f6acd39ed946b78e287238631912efd7e1..2c3d12ab78b04de81a81fc38184058463bd9be02 100644 (file)
@@ -194,6 +194,7 @@ typedef struct dom0_readconsole_st
 {
     unsigned long str;
     unsigned int count;
+    unsigned int cmd;
 } dom0_readconsole_t;
 
 typedef struct dom0_op_st
index 589754d08a135b8198db38b993b79ed9c2472d4f..375c4b22150af94d944de3f1579dd09be4141ef8 100644 (file)
@@ -6,6 +6,9 @@
  * Copyright (c) 2003 James Scott, Intel Research Cambridge
  */
 
+#ifndef __CONSOLE_H__
+#define __CONSOLE_H__
+
 /*
  * Ownership of console --- currently hardwired to dom0. This is used to see 
  * who gets the PS/2 keyboard/mouse events
@@ -43,7 +46,8 @@
 
 extern int opt_console;
 
-#define CONSOLE_RING_SIZE     16392
+#define CONSOLE_RING_SIZE      16392
+#define CONSOLE_RING_CLEAR     1
 
 typedef struct console_ring_st
 {
@@ -53,5 +57,6 @@ typedef struct console_ring_st
 
 extern console_ring_t console_ring;
 
-void init_console_ring();
-long read_console_ring(unsigned long, unsigned int);
+long read_console_ring(unsigned long, unsigned int, unsigned int);
+
+#endif